Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace IndexAlreadyExistsException with ResourceAlreadyExistsException #21494

Conversation

dimitris-athanasiou
Copy link
Contributor

@dimitris-athanasiou dimitris-athanasiou commented Nov 11, 2016

Similar to ResourceNotFoundException, a generic ResourceAlreadyExistsException will reduce the need to introduce an additional exception for each type of resource that can have that error.

At the moment, there is:

  • IndexAlreadyExistsException
  • IndexTemplateAlreadyExistsException
  • IndexShardAlreadyExistsException

This commit changes those to inherit ResourceAlreadyExistsException
as removing them would cause backwards compatibility problems.

@dimitris-athanasiou
Copy link
Contributor Author

Note that in 6.0 we could decide to delete the Index*AlreadyExistsException classes. We'd still need to keep them in 5.x for backwards compatibility. Let me know what you think and I'll adjust the PR respectively.

}

@Override
public RestStatus status() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it'd be more right to make this final.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the implication that all not found exceptions are 400 errors and IndexShardAlreadyExistsException isn't really an ResourceAlreadyExistsException because it is an internal error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is how I had it originally. Then I had a brain split about whether IndexShardAlreadyExistsException is actually a ResourceAlreadyExistsException. I am happy to change this, but I'll wait a bit in case more opinions are voiced.

@jasontedor
Copy link
Member

I think that @s1monw's thinking should be taken into consideration before this PR is integrated.

@s1monw
Copy link
Contributor

s1monw commented Nov 11, 2016

I think this PR should remove all the exceptions and replace it by ResourceAlreadyExistsException. We can't add new exceptions in minors since it's basically a wire protocol break. What we can do is to rename an existing exception to ResourceAlreadyExistsException and deprecate all the other ones we have. In 6.0 we can remove them and for 5.x we rename IndexAlreadyExistsException to ResourceAlreadyExistsException and deprecate the usage of IndexShardAlreadyExistsException and IndexTemplateAlreadyExistsException. I really think we can replace most of them with a simple IllegalStateException or IllegalArgumentException? Ideally, we don't add a new one at all :)

@dimitris-athanasiou
Copy link
Contributor Author

There are a few points here that I would like to understand better:

  • IndexShardAlreadyExistsException has a 500 HTTP status code. The other two have 400. As the one is server error and the other two user error, should we keep them separate? Or can we simply make ResourceAlreadyExistsException have a variable status code?
  • If we rename IndexAlreadyExistsException to ResourceNotFoundException in 5.x aren't we already breaking BWC? Should we consider keeping all the IndexXxxAlreadyExistsException for 5.x as they are and only remove them in 6.0?
  • Whatever decision we make for this one, should we also apply it for XxxNotFoundException? There is IndexNotFoundException, ShardNotFoundException, AliasesNotFoundException and ResourceNotFoundException.

s1monw added a commit to s1monw/elasticsearch that referenced this pull request Nov 14, 2016
…istsException`

Both exception can be replaced with java built-in exception, IAE and ISE respectively.
This should be backported partially to 5.x which the transport layer code should be preserved.

Relates to elastic#21494
@s1monw
Copy link
Contributor

s1monw commented Nov 14, 2016

Whatever decision we make for this one, should we also apply it for XxxNotFoundException? There is IndexNotFoundException, ShardNotFoundException, AliasesNotFoundException and ResourceNotFoundException.

lets not worry about this for now

IndexShardAlreadyExistsException has a 500 HTTP status code. The other two have 400. As the one is server error and the other two user error, should we keep them separate? Or can we simply make ResourceAlreadyExistsException have a variable status code?

I just looked into the code and replaced IndexShardAlreadyExistsException with IllegalStateException which maps to 500.. yet, I don't think this is important since it won't bubble up anyway. I also removed IndexTemplateAlreadyExistsException which is an IllegalArgumentException IMO. I can open up a PR soon for those two

If we rename IndexAlreadyExistsException to ResourceNotFoundException in 5.x aren't we already breaking BWC? Should we consider keeping all the IndexXxxAlreadyExistsException for 5.x as they are and only remove them in 6.0?

so on the wire protocol it will be just fine since we are not name-aware, we use an integer ID to deserialize. If you are thinking of REST layer we can just do something like this:

/*
 * Licensed to Elasticsearch under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Elasticsearch licenses this file to you under
 * the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.elasticsearch.indices;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.Index;
import org.elasticsearch.rest.RestStatus;

import java.io.IOException;

public class ResourceAlreadyExistsException extends ElasticsearchException {

    public ResourceAlreadyExistsException(Index index, String message) {
        super(message);
        setIndex(index);
    }

    public ResourceAlreadyExistsException(StreamInput in) throws IOException{
        super(in);
    }

    @Override
    public RestStatus status() {
        return RestStatus.BAD_REQUEST;
    }

    @Override
    protected String getExceptionName() {
        if (getIndex() != null) {
            // this is only for BWC and can be removed in 6.0.0
            return "index_already_exists_exception";
        } else {
            return super.getExceptionName();
        }
    }
}

s1monw added a commit that referenced this pull request Nov 14, 2016
…istsException` (#21539)

Both exception can be replaced with java built-in exception, IAE and ISE respectively.
This should be back ported partially to 5.x which the transport layer code should be preserved.

Relates to #21494
@dimitris-athanasiou
Copy link
Contributor Author

Sounds good, I will update the PR.

I summarise the decision as I understand it:

  • 6.0: Rename IndexAlreadyExistsException to ResourceAlreadyExistsException
  • 5.x: Rename IndexAlreadyExistsException to ResourceAlreadyExistsException but maintain the exception name to index_already_exists_exception when an index is set.

s1monw added a commit that referenced this pull request Nov 15, 2016
…istsException` (#21539)

Both exception can be replaced with java built-in exception, IAE and ISE respectively.
This should be back ported partially to 5.x which the transport layer code should be preserved.

Relates to #21494
@s1monw
Copy link
Contributor

s1monw commented Nov 15, 2016

++ sounds good to me @jasontedor @nik9000 WDYT?

@nik9000
Copy link
Member

nik9000 commented Nov 15, 2016

Makes sense to me.

@jasontedor
Copy link
Member

++ sounds good to me @jasontedor @nik9000 WDYT?

Makes sense to me.

+1

@dimitris-athanasiou dimitris-athanasiou force-pushed the introduce-generic-already-exists-exception branch from 21edd06 to 0afd6ad Compare November 16, 2016 13:02
@dimitris-athanasiou dimitris-athanasiou changed the title Introduce ResourceAlreadyExistsException Replace IndexAlreadyExistsException with ResourceAlreadyExistsException Nov 16, 2016
@dimitris-athanasiou
Copy link
Contributor Author

PR is now updated with latest plan.

Copy link
Contributor

@s1monw s1monw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left one comment otherwise looks good

@@ -745,7 +745,7 @@ public void testIds() {
ids.put(120, org.elasticsearch.repositories.RepositoryVerificationException.class);
ids.put(121, org.elasticsearch.search.aggregations.InvalidAggregationPathException.class);
ids.put(122, null);
ids.put(123, org.elasticsearch.indices.IndexAlreadyExistsException.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't work sorry... you can't add a new exception here it's a wire protocol break. Just reuse the 123 and add a comment that we renamed it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know! Will change ASAP.

@dimitris-athanasiou dimitris-athanasiou force-pushed the introduce-generic-already-exists-exception branch from 3ff0b48 to 06e2054 Compare November 16, 2016 15:44
@s1monw
Copy link
Contributor

s1monw commented Nov 16, 2016

for the backport I think we need to add a BWC layer here other than that this change LGTM...

@dimitris-athanasiou
Copy link
Contributor Author

I opened a backport PR at #21601.

@dimitris-athanasiou dimitris-athanasiou force-pushed the introduce-generic-already-exists-exception branch from 06e2054 to 1561ecd Compare November 16, 2016 17:53
@dimitris-athanasiou dimitris-athanasiou force-pushed the introduce-generic-already-exists-exception branch from 1561ecd to c1f95f6 Compare November 17, 2016 13:53
@markgoddard
Copy link

For those wondering how this turned out, yes it did break backwards compatibility for us as an ES API consumer.

https://review.opendev.org/#/c/724460

@dimitris-athanasiou dimitris-athanasiou deleted the introduce-generic-already-exists-exception branch April 30, 2020 08:49
@xiaojueguan
Copy link

will rpm of version 6 with this change: a75320f soon be available in your yum repo

AmitPhulera added a commit to dimagi/commcare-hq that referenced this pull request Nov 29, 2023
AmitPhulera added a commit to dimagi/commcare-hq that referenced this pull request Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants